from flask import Flask,jsonify,request,render_template
from alg import stock_info

app = Flask(__name__)

#test:show any stock
@app.route('/')
def base():
    #x = stock_info('sh.600848')
    return render_template('super_screen.html')

@app.route('/get_info',methods=['GET','POST'])
def show():
    #eg:600048
    id = request.args['id']
    print('id:',id)
    stock = stock_info('sz.'+id)
    K5 = stock.to_list(stock.Kday)
    print('k5',K5)
    macd = stock.MACD(stock.Kday)[0]
    cat = stock.cat(stock.Kday,frequecy=1)
    start = cat[-1]
    date = K5[1][start:]
    k = K5[2][start:]
    print(cat[1])
    catted_macd,dif = stock.MACD(stock.Kday)
    print(type(catted_macd[0]))
    #stock.MACD_cat(cat)
    stroke = stock.strict_stroke(cat)
    segment = stock.segement(stock.strict_stroke(cat),cat,stock.Kday)
    center,c4c = stock.center(stroke,segment)

    return jsonify(all_info = [K5,macd,[date,k],catted_macd,stroke[1],segment[0],dif,c4c])

if __name__ == "__main__":
    app.run(port=5000)
